using UnityEngine;

public class SFX_BubbleJump : MonoBehaviour
{
    public AudioClip[] randClips;
    public AudioSource audioSource;
    bool isPlaying;
    private int n;

    public void ResetPlayer()
    {
        audioSource.Stop();
        isPlaying = false;
    }

    public void Play()
    {
        isPlaying = true;
        n += 3;
    }

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Awake()
    {
        audioSource.loop = false;
        ResetPlayer();
    }

    // Update is called once per frame
    void Update()
    {
        if (isPlaying && !audioSource.isPlaying && n > 0)
        {
            var i = Random.Range(0, randClips.Length);
            audioSource.clip = randClips[i];
            audioSource.Play();
            n -= 1;
        }
        if (n == 0) ResetPlayer();
    }
}
